package com.xiaomaoguai.webkit.web.listener;

import java.util.Locale;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.StringUtils;

import com.xiaomaoguai.webkit.web.XmgWebUtils;

/**
 * @Description :
 * @FileName: LocaleContextListener.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年5月8日 下午5:16:26
 * @Version:V1.00
 */
public class LocaleContextListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		ServletContext context = contextEvent.getServletContext();
		String localeConfiguration = XmgWebUtils.getInitParameter(context, "locale");
		if (StringUtils.isNotEmpty(localeConfiguration)) {
			try {
				Locale locale = LocaleUtils.toLocale(localeConfiguration);
				Locale.setDefault(locale);
			} catch (Exception e) {
				context.log("resolve locale failure", e);
			}
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent contextEvent) {

	}
}
